import 'package:example/app/data/model/article_bean.dart';
import 'package:example/app/modules/main_module/home_page/components/article_item.dart';
import 'package:example/app/modules/main_module/home_page/components/article_skeleton.dart';
import 'package:example/app/modules/search_module/search_controller.dart';
import 'package:example/app/routes/app_pages.dart';
import 'package:example/app/widget/skeleton.dart';
import 'package:flutter/material.dart';
import 'package:example/index.dart';

class SearchContent extends StatelessWidget {
  const SearchContent({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return GetBuilder<SearchController>(
      builder: (_) {
        return ViewStateWidget<SearchController>(
          loadingWidget: SkeletonList(
            builder: (context, index) => ArticleSkeletonItem(),
          ),
          successWidget: SmartRefresher(
            controller: _.refreshController,
            enablePullDown: true,
            enablePullUp: true,
            onRefresh: _.onRefresh,
            onLoading: _.onLoadMore,
            child: ListView.builder(
              itemBuilder: (context, index) {
                return ArticleItem(
                  index: index,
                  item: _.articles[index],
                  onTap: (ArticleBean item) {
                    Get.toNamed(Routes.ARTICLE_DETAIL, arguments: item);
                  },
                );
              },
              itemCount: _.articles.length,
            ),
          ),
        );
      },
    );
  }
}
